package com.ruoyi.workShop.controller;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.workShop.domain.BdWorkshop;
import com.ruoyi.workShop.service.IBdWorkshopService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车间Controller
 *
 * @author ruoyi
 * @date 2023-11-14
 */
@Api(tags="车间管理")
@RestController
@RequestMapping("/workShop/workshop")
public class BdWorkshopController extends BaseController
{
    @Autowired
    private IBdWorkshopService bdWorkshopService;

    /**
     * 查询车间列表
     */
    @ApiOperation("查询车间列表")
    @PreAuthorize("@ss.hasPermi('workShop:workshop:list')")
    @GetMapping("/list")
    public TableDataInfo list(BdWorkshop bdWorkshop)
    {
        startPage();
        List<BdWorkshop> list = bdWorkshopService.selectBdWorkshopList(bdWorkshop);
        return getDataTable(list);
    }

    /**
     * 导出车间列表
     */
    @ApiOperation("导出车间列表")
    @PreAuthorize("@ss.hasPermi('workShop:workshop:export')")
    @Log(title = "车间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BdWorkshop bdWorkshop)
    {
        List<BdWorkshop> list = bdWorkshopService.selectBdWorkshopList(bdWorkshop);
        ExcelUtil<BdWorkshop> util = new ExcelUtil<BdWorkshop>(BdWorkshop.class);
        util.exportExcel(response, list, "车间数据");
    }

    /**
     * 获取车间详细信息
     */
    @ApiOperation("获取车间详细信息")
    @PreAuthorize("@ss.hasPermi('workShop:workshop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bdWorkshopService.getById(id));
    }

    /**
     * 新增车间
     */
    @ApiOperation("新增车间")
    @PreAuthorize("@ss.hasPermi('workShop:workshop:add')")
    @Log(title = "车间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BdWorkshop bdWorkshop)
    {
        return toAjax(bdWorkshopService.save(bdWorkshop));
    }

    /**
     * 修改车间
     */
    @ApiOperation("修改车间")
    @PreAuthorize("@ss.hasPermi('workShop:workshop:edit')")
    @Log(title = "车间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BdWorkshop bdWorkshop)
    {
        return toAjax(bdWorkshopService.updateById(bdWorkshop));
    }

    /**
     * 删除车间
     */
    @ApiOperation("删除车间")
    @PreAuthorize("@ss.hasPermi('workShop:workshop:remove')")
    @Log(title = "车间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bdWorkshopService.removeByIds(Arrays.asList(ids)));
    }
}
